package com.eastmoney.emis.edda.task.edda;

import com.eastmoney.emis.edda.domain.service.edda.EddaAuthService;
import com.eastmoney.emis.edda.domain.service.edda.EddaAuthStatusService;
import com.eastmoney.emis.edda.domain.valueobject.EddaApplyStatus;
import com.eastmoney.emis.edda.task.handler.TaskHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @description: Description
 * @projectName: EDDA-HSBC
 * @package: com.eastmoney.emis.edda.task
 * @author: 汪程程
 * @date: 2022/10/10 2:22 PM
 * @version: 1.0
 */
@Component("EddaAuthEnquiryTaskHandler")
public class EddaAuthEnquiryTaskHandler implements TaskHandler<EddaAuthEnquiryTask> {

    @Autowired
    private EddaAuthStatusService eddaAuthStatusService;
    @Autowired
    private EddaAuthService eddaAuthService;

    public EddaAuthEnquiryTaskHandler() {
    }


    @Override
    public void handle(EddaAuthEnquiryTask task) {
        EddaApplyStatus applyStatus = EddaApplyStatus.parse(task.getEddaApply().getStatus());
        if (applyStatus == EddaApplyStatus.INIT) {
            eddaAuthService.auth(task.getEddaApply());
            return;
        }
        eddaAuthStatusService.reload(task);
    }
}
